<template>
	<view class="center">
		
		<navigator :url="'../discover/houseDetail?house_id='+item.id" v-for="(item,index) in houseList">
		<view class="visitprint">	
				
				<image v-if="item.image" class="left" :src="siteUrl+item.image"></image>
				<image v-else class="left" :src="siteUrl+item.images.split(',',1)"></image>
				
				
				<view class="right">
					<view class="title">
						{{item.title}}
					</view>
					<view class="location">
						<image src="/static/img/icon-location.png"></image>
						<view class="note">{{item.location_near}}</view>
					</view>
					<view class="price">
						<font style="font-size:40rpx;color:#FF635C">{{item.price}}</font>元/月
					</view>				
				</view>		
		</view>
		</navigator>
		<uni-load-more  :loadingType="loadingType" :contentText="contentText" :status="status"></uni-load-more>
		
		
	</view>
</template>

<script>
    var _self,
    page = 1,
    timer = null;
    import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue'
	export default {
		components: {
		   uniLoadMore 
		},
		data() {
			return {
				title: 'Hello',
				houseList:[],
				siteUrl:this.websiteUrl,
				status: 'more',
				loadingText: '加载中...',
				loadingType: 2,//定义加载方式 0---contentdown  1---contentrefresh 2---contentnomore
				contentText: {
				    contentdown:'上拉显示更多',
				    contentrefresh: '正在加载...',
				    contentnomore: '没有更多数据了'
				}
			}
		},
		onLoad(){
			_self = this
			this.gethouseList()			
		},
		onPullDownRefresh: function() {
			//下拉刷新的时候请求一次数据			
		    this.gethouseList()					
		},
		onReachBottom: function() {
			//触底的时候请求数据，即为上拉加载更多
			//为了更加清楚的看到效果，添加了定时器
		    if (timer != null) {
		        clearTimeout(timer);
		    }		   
			 _self.getmorenews();
		},	
		methods: {
			getmorenews: function() {
				if(_self.status !== 'more'){
					return false
				}						    
				_self.status = 'loading'
			    uni.showNavigationBarLoading();//显示加载动画
			    uni.request({
			        url:this.websiteUrl+'/userapi.php/center/footprintList?page='+page,
			        method: 'POST',
					header: {
						'content-type':'application/x-www-form-urlencoded'						
					},
					data: {
						token:uni.getStorageSync('token'),						
					},					
			        success: function(res) {						
			            if (res.data.data.data.length == 0) {//没有数据			                
							_self.status = 'noMore'								
			                uni.hideNavigationBarLoading();//关闭加载动画							
			                return false;
			            }
			            page++;//每触底一次 page +1										
			            _self.houseList = _self.houseList.concat(res.data.data.data);//将数据拼接在一起			           
						console.log(_self.houseList)
						_self.status = 'more'					
			            uni.hideNavigationBarLoading();//关闭加载动画
			        }
			    });
			},			
			gethouseList(){
				page = 1;
				_self.status = 'more'
				uni.showNavigationBarLoading();	
				uni.request({
					url: this.websiteUrl+'/userapi.php/center/footprintList?page=1',
					method: 'GET',
					header: {
						'content-type':'application/x-www-form-urlencoded'				  
					},
					data: {token:uni.getStorageSync('token')},
					success: res => {
						page++
						_self.houseList = res.data.data.data
						console.log(_self.houseList)
						uni.hideNavigationBarLoading();
						uni.stopPullDownRefresh();//得到数据后停止下拉刷新					
					},					
				});
			}			
		}
	}
</script>

<style>
    .center {	
		display: flex;
		flex-direction: column;
		align-items: center;
		width:100%;
	}
	
	.visitprint{
		width:100%;
		height: 264rpx;
	}
	
	.visitprint .left{
		padding-left:32rpx;
		width:240rpx;
		height: 200rpx;
		padding-top:32rpx;
		float:left;
	}
	
	.visitprint .right{
		width:422rpx;
		height: 200rpx;
		margin-left:24rpx;
		float:left;
	}
	
	.right .title{
		font-size:30rpx;
		line-height: 42rpx;
		color:#373737;
		padding-top:32rpx;
	}
	
	.right .location{
		width:100%;
		height: 34rpx;
		margin-top:12rpx;
	}
	
	.right .location image{
		width:28rpx;
		height: 28rpx;
		float:left;
	}
	
	.right .location .note{
		float:left;
		font-size:24rpx;
		line-height: 34rpx;
		color:#999999;
		margin-left:12rpx;
	}
	
	
	.right .price{
		font-size:32rpx;
		line-height:48rpx;
		margin-top:12rpx;
		
	}
	
	
	
	
	
	
	
	
	
	
</style>
